﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Oblivio.Framework;

namespace MSH.Common.Helpers
{
    /// <summary>
    /// De SMSHelper is verantwoordelijk voor het versturen van SMS berichten via Mollie.
    /// </summary>
    public static class SMSHelper
    {
        private static MollieSMS sms; 

        static SMSHelper()
        {
            sms = new MollieSMS();
            sms.Gateway = System.Configuration.ConfigurationManager.AppSettings["mollie.gateway"];
            sms.Username = System.Configuration.ConfigurationManager.AppSettings["mollie.username"];
            sms.Password = System.Configuration.ConfigurationManager.AppSettings["mollie.password"];
            sms.Originator = System.Configuration.ConfigurationManager.AppSettings["mollie.smsName"];
            sms.UseSecureConnection = true;
        }

        /// <summary>
        /// Verstuurt een SMS via Mollie
        /// </summary>
        /// <param name="mobilePhoneNumber">Telefoonnummer van de ontvanger.</param>
        /// <param name="message">Bericht dat verzonden moet worden.</param>
        /// <returns>Boolean die aangeeft of de SMS succesvol verzonden is.</returns>
        public static bool SendSMS(String mobilePhoneNumber, String message)
        {
            sms.Message = message;
            sms.Recipients = mobilePhoneNumber;

            try
            {
                sms.Send();
                if (sms.Success)
                    return true;
                else
                {
                    //log de fout
                    LogHelper.LogMessage(string.Format("SMSHelper.SendSMS(): {0}: {1}", sms.ResultCode, sms.ResultMessage));
                    return false;
                }
            }
            catch (Exception e)
            {
                //log de fout
                LogHelper.LogMessage(string.Format("SMSHelper.SendSMS(): {0}: {1}, {2}", sms.ResultCode, sms.ResultMessage, e.ToString()));
                return false;
            }
        }

    }
}
